<?php
include_once('common/header.php');			
if($AppUI->id <=0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if(!Vfriend_Function::isValidLink($strRefer)) {
	Vfriend_Function::redirect(LINK_NEW);
}

$strName			= $objRequest->getParam('pname', '');
//$intCategoryId		= $objRequest->getParam('pcategoryid', 0);
$intSubCategoryId	= $objRequest->getParam('pcategoryid', 0);
$oFile				= $_FILES['pimage'];
$strContent			= $objRequest->getParam('pcontent','');
$strTags			= $objRequest->getParam('ptags','');
$strSrcLink			= $objRequest->getParam('psrc_link', '');
$strImage			= '';
$intError			= 0;
$strContent			= Vfriend_Function::stripTags($strContent,5);
if(!$intSubCategoryId) $intError = 10;
elseif($strName == '') $intError = 1;
elseif($strName != '' && strlen($strName) < 5) $intError = 2;
elseif(!isset($oFile['name'])) $intError = 11;
elseif($strContent == '') $intError = 5;
elseif($strContent != '' && strlen($strContent)<20) $intError = 6;

if($intError == 0 && isset($oFile['name']) && $oFile['name'] != '') {
	$arrImage = Globals::uploadNews($oFile);	
	if($arrImage['error'] == "") {
		$strImage = $arrImage['path'];
	} else {
		$intError = 3;
	}
}
if($intError == 0) {
	if(isset($_SESSION['sNewsError'])) unset($_SESSION['sNewsError']);
	if(isset($_SESSION['sNewsParam'])) unset($_SESSION['sNewsParam']);
	$strShort 		= Vfriend_Function::wordCut($strContent);
	$intCategoryId	= 0;
	$objNews		= new News();
	$objNews->add($AppUI->id, $strImage, $strName, Vfriend_Function::stripTags($strContent,5), $strShort, $strTags, $intCategoryId, $intSubCategoryId, $strSrcLink);
	Vfriend_Function::setMsg($arrMessage[1]);
	Vfriend_Function::redirect(LINK_NEWS);
}
if($intError > 0) {
	$_SESSION['sNewsError']	= $arrError[$intError];
	$_SESSION['sNewsParam']	= $objRequest->getParams();
	Vfriend_Function::redirect(LINK_NEWS_ADD);
}
?>
